import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get_navigation/get_navigation.dart';
import 'package:psi/utils/utils.dart';
import 'package:psi/utils/widget_util.dart';
import 'package:psi/widgets/gesture.dart';

import '../generated/assets.dart';

class Avatar extends StatelessWidget {
  String? imagePath;
  double size;
  VoidCallback? onTap;

  Avatar({this.imagePath, this.size = 80, this.onTap});



  @override
  Widget build(BuildContext context) {
    return ClickWidget(
      onTap: onTap,
      child: Container(
        width: size,
        height: size,
        clipBehavior: Clip.antiAlias,
        decoration: BoxDecoration(
          borderRadius: BorderRadius.all(Radius.circular(size / 2)),
          border: Border.all(color: Colors.white, width: 2),
        ),
        child: ClipOval(
          child: imagePath == null ? WidgetUtil.assetImage(R.placeholder) : CachedNetworkImage(
            imageUrl: imagePath!,
            fit: BoxFit.cover,
            placeholder: (context, url) => WidgetUtil.assetImage(R.placeholder),
            errorWidget: (context, url, error) => WidgetUtil.assetImage(R.placeholder),
          ),
        ),
      ),
    );
  }
}
